package cn.b.sky.admin.model;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;

import java.util.Date;
import java.util.List;

/**
 * 
 * <strong>Title : Page.java<br></strong>
 * <strong>Package : cn.b.sky.common.model<br></strong>
 * <strong>Description : </strong>分页对象. 包含数据及分页信息.<br> 
 * <strong>Create on : 2015-7-1 下午1:52:26<br></strong>
 * <p>
 * @author lidapeng<br>
 * @version <strong>v1.0.0</strong><br>
 * <br>
 * <strong>修改历史:</strong><br>
 * 修改人 | 修改日期 | 修改描述<br>
 * -------------------------------------------<br>
 * <br>
 * <br>
 */
public class Page {

  /**
   * 工厂代码
   */
  private String siteCode;

  /**
   * 创建人
   */
  private String createUser;

  /**
   * 开始创建时间
   */
  private String minCreateDateTime;

  /**
   * 结束创建时间
   */
  private String maxCreateDateTime;

  /**
   * 修改人
   */
  private String modifyUser;

  /**
   * 开始修改时间
   */
  private String minModifyDateTime;

  /**
   * 结束修改时间
   */
  private String maxModifyDateTime;

  /**
    * 每页显示条数
    */
  private int numPerPage = 20;

  /**
   * 当前页号
   */
  private int pageNum = 1;

  /**
   * 开始行
   */
  private int startRow;

  /**
   * 结束行 -1 表示全部
   */
  private int endRow;

  /**
   * 总条数
   */
  private long totalCount;

  /**
   * 返回结果集
   */
  private List data;

  /**
   * 排序字段
   */
  private String orderField;

  /**
   * 正序倒序
   * 默认降序
   */
  private String orderDirection = "desc";

  /**
   * 高级查询打开状态
   */
  private String advancedStatus;

  /**
   * 多个字段排序，前台传回来的排序字符串
   */
  private String ordersString;

  @DateTimeFormat(iso = ISO.DATE_TIME, pattern = "yyyy-MM-dd")
  private Date modifyDateTimeSt;

  @DateTimeFormat(iso = ISO.DATE_TIME, pattern = "yyyy-MM-dd")
  private Date modifyDateTimeEd;

  @DateTimeFormat(iso = ISO.DATE_TIME, pattern = "yyyy-MM-dd")
  private Date createDateTimeSt;

  @DateTimeFormat(iso = ISO.DATE_TIME, pattern = "yyyy-MM-dd")
  private Date createDateTimeEd;

  public Page() {
    // Do nothing
  }

  /**
   * 默认构造方法
   * 
   * @param numPerPage
   *            当前页码
   * @param totalCount
   *            数据库中总记录条数
   * @param pageNum
   *            本页容量
   * @param data
   *            本页包含的数据
   */
  public Page(int numPerPage, int totalCount, int pageNum, List<Object> data) {
    this.pageNum = pageNum;
    this.numPerPage = numPerPage;
    this.totalCount = totalCount;
    this.data = data;
  }

  public Page(int totalCount, List<Object> data) {
    this.totalCount = totalCount;
    this.data = data;
  }

  public String getSiteCode() {
    return siteCode;
  }

  public void setSiteCode(String siteCode) {
    this.siteCode = siteCode;
  }

  public String getCreateUser() {
    return createUser;
  }

  public void setCreateUser(String createUser) {
    this.createUser = createUser;
  }

  public String getModifyUser() {
    return modifyUser;
  }

  public void setModifyUser(String modifyUser) {
    this.modifyUser = modifyUser;
  }

  public String getMinCreateDateTime() {
    return minCreateDateTime;
  }

  public void setMinCreateDateTime(String minCreateDateTime) {
    this.minCreateDateTime = minCreateDateTime;
  }

  public String getMaxCreateDateTime() {
    return maxCreateDateTime;
  }

  public void setMaxCreateDateTime(String maxCreateDateTime) {
    this.maxCreateDateTime = maxCreateDateTime;
  }

  public String getMinModifyDateTime() {
    return minModifyDateTime;
  }

  public void setMinModifyDateTime(String minModifyDateTime) {
    this.minModifyDateTime = minModifyDateTime;
  }

  public String getMaxModifyDateTime() {
    return maxModifyDateTime;
  }

  public void setMaxModifyDateTime(String maxModifyDateTime) {
    this.maxModifyDateTime = maxModifyDateTime;
  }

  /**
     * 获取开始行
     * @return
     */
  public int getStartRow() {

    this.startRow = (pageNum - 1) * numPerPage + 1;

    return this.startRow;
  }

  public void setStartRow(int startRow) {
    this.startRow = startRow;
  }

  public int getEndRow() {
    if (this.endRow != -1) {
      this.endRow = (this.getStartRow() - 1) + numPerPage;
    }

    return endRow;
  }

  public void setEndRow(int endRow) {

    this.endRow = endRow;
  }

  public int getPageNum() {
    return pageNum;
  }

  public void setPageNum(int pageNum) {
    this.pageNum = pageNum;
  }

  public int getNumPerPage() {
    return numPerPage;
  }

  public void setNumPerPage(int numPerPage) {
    this.numPerPage = numPerPage;
  }

  public long getTotalCount() {
    return totalCount;
  }

  public void setTotalCount(long totalCount) {
    this.totalCount = totalCount;
  }

  public List getData() {
    return data;
  }

  public void setData(List data) {
    this.data = data;
  }

  public String getOrderField() {
    return orderField;
  }

  public void setOrderField(String orderField) {
    this.orderField = orderField;
  }

  public String getOrderDirection() {
    return orderDirection;
  }

  public void setOrderDirection(String orderDirection) {
    if (!StringUtils.isBlank(orderDirection)) {
      this.orderDirection = orderDirection;
    } else {
      this.orderDirection = "desc";
    }

  }

  public String getAdvancedStatus() {
    return advancedStatus;
  }

  public void setAdvancedStatus(String advancedStatus) {
    this.advancedStatus = advancedStatus;
  }

  public Date getModifyDateTimeSt() {
    return modifyDateTimeSt;
  }

  public void setModifyDateTimeSt(Date modifyDateTimeSt) {
    this.modifyDateTimeSt = modifyDateTimeSt;
  }

  public Date getModifyDateTimeEd() {
    return modifyDateTimeEd;
  }

  public void setModifyDateTimeEd(Date modifyDateTimeEd) {
    this.modifyDateTimeEd = modifyDateTimeEd;
  }

  public Date getCreateDateTimeSt() {
    return createDateTimeSt;
  }

  public void setCreateDateTimeSt(Date createDateTimeSt) {
    this.createDateTimeSt = createDateTimeSt;
  }

  public Date getCreateDateTimeEd() {
    return createDateTimeEd;
  }

  public void setCreateDateTimeEd(Date createDateTimeEd) {
    this.createDateTimeEd = createDateTimeEd;
  }

  public String getOrdersString() {
    return ordersString;
  }

  public void setOrdersString(String ordersString) {
    this.ordersString = ordersString;
  }

}
